<?php
	include_once $_SERVER['DOCUMENT_ROOT'] . '/projet_mosquee/AMC/conf/conf.site.inc.php';
	// include_once $_SERVER['DOCUMENT_ROOT'] . '/inscriptions/conf/conf.site.inc.php';
	
	include_once ELEVE_CLASS;
	include_once INSCRIPTION_CLASS;
	include_once FUNCTIONS_FILE;
	
	connexion ();
	$eleve = new eleve($db);
							 
	$result = $eleve->eleveSearch ($_POST["idParent"]);
        $html = "";
    
	if ($result) {
		$paiment = new inscription($db);
		$frais_inscription = $paiment->getFraisInscription ($_POST["idParent"], date('Y'));
		
		foreach ($result as $aEleve) {
			$inscription = $eleve->eleveGetInscription($aEleve["ID_ELEVE"]);
			
			$arabe = "";
			$coran = "";
			
			if ($inscription[0]["ARABE"] == "1") {
				$arabe = "checked";
			}
			if ($inscription[0]["CORAN"] == "1") {
				$coran = "checked";
			}
			
			if ($aEleve["SEXE"] == "M") {
				$class_box = "box_masculin";
			}
			else {
				$class_box = "box_feminin";
			}
			
			
			$html .= "
			<div class='eleve_box " . $class_box . "' idEleve='" . $aEleve["ID_ELEVE"] . "'>
				" . $aEleve["PRENOM"] . " " . $aEleve["NOM"] . " - " . $eleve->age($aEleve["DATE_NAISSANCE"]) . " Ans
				<div>
					<input idInscription='" . $inscription[0]["ID_INSCRIPTION"] . "' type='checkbox' " . $arabe . " id='arabe_".$aEleve["ID_ELEVE"]."' name='arabe_".$aEleve["ID_ELEVE"]."' />
					<label for='arabe_".$aEleve["ID_ELEVE"]."'><span></span>Arabe</label>
				</div>
				<div>
					<input idInscription='" . $inscription[0]["ID_INSCRIPTION"] . "' type='checkbox' " . $coran . " id='coran_".$aEleve["ID_ELEVE"]."' name='coran_".$aEleve["ID_ELEVE"]."' />
					<label for='coran_".$aEleve["ID_ELEVE"]."'><span></span>Coran</label>
				</div>
			</div>";
		}
                $html .= "<div class='addEleve'>
                                <input type='image' idParent='" . $_POST["idParent"] . "' class ='addButton' id='btnNewEleve' name='eleveAdd' src='images/ajouter.png' />
                        </div>
						
						<script>
							$('input[id^=\"arabe_\"]').click (function() {
								var value = $(this).is(':checked');
								var idInscription = $(this).attr('idInscription');
								console.log(idInscription);
								if (value == true) {
									inscrirArabe (idInscription);
								}
								else {
									desinscrirArabe (idInscription);
								}
							});

							$('input[id^=\"coran_\"]').click (function() {
								var value = $(this).is(':checked');
								var idInscription = $(this).attr('idInscription');
								if (value == true) {
									inscrirCoran (idInscription);
								}
								else {
									desinscrirCoran (idInscription);
								}
							});

							$('input#montant_total').val('');
							$('input#montant_a_payer').val('');
							$('input#id_frais_inscription').val('');
							$('input#montant_total').val(" . $frais_inscription[0]["MONTANT_DU"] . ");
							$('span#restant_a_payer').html(" . $frais_inscription[0]["RESTANT_A_PAYE"] . "+'&euro;');
							$('input#id_frais_inscription').val(" . $frais_inscription[0]["ID_FRAIS_INSCRIPTION"] . ");
							$('input#id_parent_frais').val(" . $_POST["idParent"] . ");
						</script>";
	}
	else {
		$html .= "<div class='eleve_box box_masculin'>
					<div class='eleveText'>Pas d'enfant inscrit pour ce parent</div>
					<div class='btn_no_eleve'>
						<input type='image' idParent='" . $_POST["idParent"] . "' class ='addButton' id='btnNewEleve' name='eleveAdd' src='images/ajouter.png' />
					</div>
				</div>
                                ";
	}
	
	$html .= "<script>
                    $(document).ready(function() {
                        $('input#btnNewEleve').click(function() {
							$('#createEleve').bPopup({
								//contentContainer:'.content',
								loadUrl: 'forms/createEleve.php?idParent=".$_POST["idParent"]."' //Uses jQuery.load()
							});
						});
                    });
                </script>";
	
	echo $html;
	
	$eleve->_eleve();
?>